﻿using CL.Business.BLL;
using CL.Business.Entity;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace CL.UnionWeb
{
    public partial class ForgetPsw : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if ("POST" == Request.RequestType)
            {
                var userInfo = new AccountEntity();
                userInfo.AccountCode = Request["useraccount"].ToString();
                userInfo.AccountPwd = Request["userpwd"].ToString();
                userInfo.UserMobile = Request["userPhone"].ToString();
                string vCode = Request["phoneCheck"].ToString();
                string sumitPsw = Request["checkuserpwd"].ToString();

                if (string.IsNullOrEmpty(userInfo.AccountCode) ||
                  string.IsNullOrEmpty(userInfo.AccountPwd) ||
                  string.IsNullOrEmpty(vCode) ||
                  string.IsNullOrEmpty(sumitPsw) ||
                  string.IsNullOrEmpty(userInfo.UserMobile)
                  )
                {
                    SendMsgToView("参数错误", "/ForgetPsw.aspx");
                }

                if(userInfo.AccountPwd != sumitPsw)
                {
                    SendMsgToView("输入的两次密码不一致.", "/ForgetPsw.aspx");
                }

                var bll = new AccountBLL();
                var ret = bll.ForgetPassword(userInfo, vCode);
                if (0 == ret.Code)
                {
                    //记录
                    userInfo = bll.QueryEntityByMoblie(userInfo.UserMobile);
                    ShareRecordEntity shareRecord = new ShareRecordEntity();
                    shareRecord.AccountID = userInfo.AccountID;
                        shareRecord.ShareTime = DateTime.Now;
                        shareRecord.ShareType = 4;
                        new ShareRecordBLL().InsertEntity(shareRecord);
                        SendMsgToView("修改成功!  ", "/Login.aspx");
                }
                else
                {
                    SendMsgToView("修改失败! ", "/ForgetPsw.aspx");
                }
            }
        }

        protected void SendMsgToView(string msg, string url = null)
        {
            if (string.IsNullOrEmpty(url))
                Response.Write("<script >alert(\"" + msg + "\");</script>");
            else
                Response.Write("<script >alert(\"" + msg + "\");location.href='" + url + "';</script>");
            Response.End();
        }
    }
}